package com.qf.bank.funprovider.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qf.bank.funapi.po.Fun;
import com.qf.bank.funapi.vo.FunVo;
import com.qf.bank.funprovider.mapper.FunMapper;
import com.qf.bank.funprovider.service.FunService;
import org.bouncycastle.util.Pack;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lwf
 * @since 2019-12-05
 */
@Service
public class FunServiceImpl extends ServiceImpl<FunMapper, Fun> implements FunService {

    @Resource
    private FunMapper funMapper;
    @Override
    public List<Fun> getFunByType(String funType){
        List<Fun> byType = funMapper.getFunByType(funType);
        return byType;
    }
    @Override
    public Page<Fun> pageWithCondition(FunVo funVo) {
        QueryWrapper<Fun> wrapper = new QueryWrapper<>();
        if (funVo != null) {
            if (funVo.getFunId() != null) {
                wrapper.lambda().like(Fun::getFunId, funVo.getFunId());
            }
            if (funVo.getFunDate() != null) {
                wrapper.lambda().like(Fun::getFunDate, funVo.getFunDate());
            }
            if (funVo.getFunImage() != null) {
                wrapper.lambda().like(Fun::getFunImage, funVo.getFunImage());
            }
            if (funVo.getFunTips() != null) {
                wrapper.lambda().like(Fun::getFunTips, funVo.getFunTips());
            }
            if (funVo.getFunTitle() != null) {
                wrapper.lambda().like(Fun::getFunTitle, funVo.getFunTitle());
            }
            if (funVo.getFunType() != null) {
                wrapper.lambda().like(Fun::getFunType, funVo.getFunType());
            }
        }
        return (Page<Fun>)
                baseMapper.selectPage(new Page<>(funVo.getCurrent(),funVo.getSize()),wrapper);
    }

}
